#!usr/bin/env python3
# -*- coding: utf-8 -*-

from urllib.request import urlopen
from urllib.error import HTTPError,URLError

from bs4 import BeautifulSoup

def get_title(url):
    try:
        html = urlopen(url)
    except (HTTPError,URLError) as e:
        print(e)
    
    try:
        bsObj = BeautifulSoup(html.read(),'html.parser') #指定解析器类型 不然会报警告
        title = bsObj.h4
        
    except AttributeError as e:        
        print(e)
        return None
    
    return title

url = "http://pythonscraping.com/pages/page1.html"
url = "http://www.ituring.com.cn/"



#html = urlopen("https://www.hao123.com")

title = get_title(url)
print(title)